
package hz.mobileproject.pda.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.Response_loadPrisonerList;
import hz.mobileproject.pda.listener.Send_end_Callroll_inter;


/**
 * Created by YOLANDA on 2016/7/22.
 */
public class ClearPersonAdapter extends  RecyclerView.Adapter<ClearPersonAdapter.ViewHolder> {


    public List<Response_loadPrisonerList> datas = null;
    private Send_end_Callroll_inter callroll_inter;
    private Boolean onOff;

    public ClearPersonAdapter(List<Response_loadPrisonerList> datas) {
        this.datas = datas;
        this.onOff=false;
    }
    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_person,viewGroup,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }
    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
//        viewHolder.mTextView.setText(datas[position]);
        viewHolder.mTextView.setText(String.valueOf(datas.get(position).getPrisoner_id()));
        viewHolder.tv_NAME.setText(String.valueOf(datas.get(position).getPrisoner_name()));
        viewHolder.tv_no.setText(String.valueOf(datas.get(position).getDepartment_name()));


        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnAllTalkItemClickListener != null) {
                    mOnAllTalkItemClickListener.onAllTalkItemClick(position,viewHolder.itemView,datas);
                }
            }
        });

    }
    //获取数据的数量
    @Override
    public int getItemCount() {

        return datas==null?0:datas.size();
    }
    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;
        public TextView tv_NAME;
        public TextView tv_no;
        public ViewHolder(View view){
            super(view);
            mTextView = (TextView) view.findViewById(R.id.PR_id);
            tv_NAME = (TextView) view.findViewById(R.id.tv_NAME);
            tv_no = (TextView) view.findViewById(R.id.tv_no);
        }
    }

    public void removeItem(Response_loadPrisonerList model) {
        int position = datas.indexOf(model);
        LogUtils.e("position():"+position+"");
        /*if (position!=0){
            datas.remove(position);
            notifyItemRemoved(position);//Attention!
        }*/

                for (int i=0;i<datas.size();i++){
                    if (model.getPrisoner_id().equals(datas.get(i).getPrisoner_id())){
                    datas.remove(i);
//                notifyItemRemoved(i);//Attention!
                    notifyDataSetChanged();
                    break;
                }

            }

    }

    public void removeBean(Response_loadPrisonerList model) {
        datas.remove(model);
        notifyDataSetChanged();
    }

    public int getCount() {
        return datas.size();
    }








    public void addData(List<Response_loadPrisonerList> datass) {
        datas.clear();
         datas.addAll(datass);
        notifyDataSetChanged();
    }

    public interface OnAllTalkItemClickListener {
        void onAllTalkItemClick(int position, View view, List<Response_loadPrisonerList> datas);
    }

    private ClearPersonAdapter.OnAllTalkItemClickListener mOnAllTalkItemClickListener;

    public void setOnAllTalkItemClickListener(ClearPersonAdapter.OnAllTalkItemClickListener onAllTalkItemClickListener) {
        this.mOnAllTalkItemClickListener = onAllTalkItemClickListener;
    }

}
